package com.zzy.jkb.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zzy.jkb.api.CommonResult;
import com.zzy.jkb.entity.PlaceCode;
import com.zzy.jkb.entity.VaccineHistory;
import com.zzy.jkb.service.IPlaceCodeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.UUID;

/**
 * <p>
 * 场所码信息 前端控制器
 * </p>
 *
 * @author zzy
 * @since 2023-02-03
 */
@Controller
@RequestMapping("/jkb/placeCode")
public class PlaceCodeController {


    @Autowired
    IPlaceCodeService iPlaceCodeService;

    @RequestMapping(path = "/save", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation("申请场所码")
    public CommonResult list(@RequestBody PlaceCode placeCode) {

        //根据身份证号判断
        int count = iPlaceCodeService.count(Wrappers.lambdaQuery(PlaceCode.class).eq(PlaceCode::getIdentityNo, placeCode.getIdentityNo()));
        if (count > 0) {
            return CommonResult.validateFailed("每个人只能申请一个场所码");
        }
        //场所码是一个随机UUID字符串
        placeCode.setDimensionalBarcode(UUID.randomUUID().toString());
        return CommonResult.success(iPlaceCodeService.save(placeCode));
    }

}
